﻿/*********************************************************************
 版权所有: 版权所有(C) 2010 ,熙软研发部
 模块编号:  Business_YiWu_PlanAdd.aspx.cs
 作    者:高文华
 编写日期:2010-02-04
 审    核:
 审核日期:
 描    述:预约信息新增页面
...........................................................................
如果模块有修改，则每次修改添加以下注释(以系统上线后为基准)：

 *********************************************************************/

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Business_YiWu_PlanAdd : WebUI.Page.SendMessagePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {


            if (Request.QueryString["hospitalid"] != null && Request.QueryString["hospitalid"].ToString() != "")
            {
                lblShowTimeCheck.Text = "可预约";
                //医院
                lblHospitalID.Text = Request.QueryString["hospitalid"].ToString();
                lblHospitalName.Text = GetHospitalName(Request.QueryString["hospitalid"].ToString());
                //主诉
                txtContent.Text = "无";


                //绑定科室
                BindDropDownListforDep(ddlDep);

                //科室
                lblDepartmentID.Text = ddlDep.SelectedValue.ToString();
                lblDepartmentName.Text = ddlDep.SelectedItem.Text.ToString();
                //绑定时间日期
                BindDropDownListBookDay(ddlbookday);
                //绑定预约时间段
                BindDropDownListBookTime(ddltime);
                //预约时段人数状态
                lblShowTimeCheck.Text = CheckBookNum(int.Parse(lblDepartmentID.Text), System.Convert.ToDateTime(ddlbookday.SelectedValue.ToString()), int.Parse(ddltime.SelectedValue.ToString()));
                pnlShowFile.Visible = false;
            }
            else
            {
                //Response.Redirect("index.html");

                //测试逻辑
                Response.Redirect("PlanManage.aspx");
            }
        }
    }

    #region  绑定查询类型(绑定科室名称及ID)
    /// <summary>
    /// 绑定查询类型(绑定科室名称及ID)
    /// </summary>
    /// <param name="dl"> 下拉框控件</param>
    protected void BindDropDownListforDep(DropDownList dldep)
    {
        dldep.Items.Clear();

        Cisoft.YiWu.BLL.DepartmentInfoBO blldep = new Cisoft.YiWu.BLL.DepartmentInfoBO();
        DataSet ds = blldep.GetAllList();

        if (ds.Tables[0].Rows.Count > 0)
        {
            //dldep.Items.Add(new ListItem("==全部科室==", "0"));
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                dldep.Items.Add(new ListItem(ds.Tables[0].Rows[i]["DI_DepartmentlName"].ToString(), ds.Tables[0].Rows[i]["DI_DepartmentID"].ToString()));
            }
        }
        else
        {
            //无科室
            dldep.Items.Add(new ListItem("暂无科室记录", ""));
        }
    }
    #endregion

    #region  预约时段人数状态
    /// <summary>
    /// 预约时段人数状态
    /// </summary>
    /// <param name="dl"> 下拉框控件</param>
    protected string CheckBookNum(int depid, DateTime bookday, int sliceid)
    {
        //计划预约人数
        int plannum = 0;
        Cisoft.YiWu.BLL.TimeSliceBO bll = new Cisoft.YiWu.BLL.TimeSliceBO();
        Cisoft.YiWu.Model.TimeSliceMO model = new Cisoft.YiWu.Model.TimeSliceMO();
        model = bll.GetModel(sliceid);
        if (model != null)
        {
            plannum = int.Parse(model.TS_SlicePlanNum.ToString());
        }
        else
        {
            return "该科室预约时段获取数据故障";
        }

        //实际预约人数
        int realnum = 0;

        Cisoft.YiWu.BLL.PlanInfoBO bllplan = new Cisoft.YiWu.BLL.PlanInfoBO();
        Cisoft.YiWu.Model.PlanInfoMO modelplan = new Cisoft.YiWu.Model.PlanInfoMO();

        DataSet ds = bllplan.GetListBySliceidAndBook(sliceid, bookday);
        if (ds.Tables[0].Rows.Count > 0)
        {
            //存在实际预约人员
            if (ds.Tables[0].Rows.Count < plannum)
            {
                return "可预约";
            }
            else
            {
                return "预约已满，请选择其他时段";
            }
        }
        else
        {
            return "可预约";
        }
    }
    #endregion


    #region  绑定第二天开始的后七天
    /// <summary>
    /// 绑定第二天开始的后七天
    /// </summary>
    /// <param name="dl"> 下拉框控件</param>
    protected void BindDropDownListBookDay(DropDownList dlday)
    {
        dlday.Items.Clear();
        DateTime nowday = DateTime.Now;

        for (int i = 1; i < 8; i++)
        {
            string strday = nowday.AddDays(i).ToString("yyyy-MM-dd");

            string strshowday = Cisoft.IntegrationSystem.Common.DateTimeHelper.GetWeekDay(nowday.AddDays(i));

            dlday.Items.Add(new ListItem(nowday.AddDays(i).ToString("yyyy年MM月dd日") + "   " + strshowday, strday));
        }
    }
    #endregion

    #region  绑定预约时间段
    /// <summary>
    /// 绑定预约时间段
    /// </summary>
    /// <param name="dl"> 下拉框控件</param>
    protected void BindDropDownListBookTime(DropDownList dltime)
    {
        dltime.Items.Clear();

        Cisoft.YiWu.BLL.TimeSliceBO blltimeslice = new Cisoft.YiWu.BLL.TimeSliceBO();
        DataSet ds = blltimeslice.GetListByDepartmentid(int.Parse(lblDepartmentID.Text.ToString()));

        if (ds.Tables[0].Rows.Count > 0)
        {
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                dltime.Items.Add(new ListItem(ds.Tables[0].Rows[i]["TS_SliceName"].ToString(), ds.Tables[0].Rows[i]["TS_SliceID"].ToString()));
            }
        }
        else
        {
            //无预约时段安排
            ibtnUpdate.Visible = false;
            lblShowTimeCheck.Text = "该科室暂未开通预约业务";
        }


    }
    #endregion


    #region 根据数字ID返回医院名字
    public string GetHospitalName(string id)
    {
        string hospitalname = "";

        Cisoft.YiWu.BLL.HospitalInfoBO bllHospital = new Cisoft.YiWu.BLL.HospitalInfoBO();
        Cisoft.YiWu.Model.HospitalInfoMO modelHospital = new Cisoft.YiWu.Model.HospitalInfoMO();

        modelHospital = bllHospital.GetModel(int.Parse(id));

        if (modelHospital != null)
        {
            hospitalname = modelHospital.HI_HospitalName;
        }

        return hospitalname;
    }
    #endregion

    #region 根据ID返回科室名称
    public string GetDepartmentName(string id)
    {
        string strDepartmentName = "";

        Cisoft.YiWu.BLL.DepartmentInfoBO blldep = new Cisoft.YiWu.BLL.DepartmentInfoBO();
        Cisoft.YiWu.Model.DepartmentInfoMO modeldep = new Cisoft.YiWu.Model.DepartmentInfoMO();

        modeldep = blldep.GetModel(int.Parse(id));

        if (modeldep != null)
        {
            strDepartmentName = modeldep.DI_DepartmentlName;
        }

        return strDepartmentName;
    }
    #endregion

    #region 预约事件
    protected void ibtnUpdate_Click(object sender, ImageClickEventArgs e)
    {
        lblShowTimeCheck.Text = CheckBookNum(int.Parse(lblDepartmentID.Text), System.Convert.ToDateTime(ddlbookday.SelectedValue.ToString()), int.Parse(ddltime.SelectedValue.ToString()));

        Session.Remove("InfoArray");

        lblChecktxtage.Text = "";
        lblCheckMobile.Text = "";
        lblChecktxtContent.Text = "";

        //DateTime ReservationTime = System.Convert.ToDateTime(ddlbookday.SelectedValue.ToString());
        //DateTime ReservationTimeOver=DateTime.Now.AddDays(7);

        //if(ReservationTime<DateTime.Now.AddDays(-1)||ReservationTime>ReservationTimeOver)
        //{
        //    lblShowTimeCheck.Text = "时间超出预约范围。请重新选择";
        //    return;
        //}

        //if (ReservationTime.ToShortDateString == DateTime.Now.ToShortDateString)
        //{
        //    //上下午判定
        //    if (ddltime.SelectedValue.ToString() == "上午" && DateTime.Now > ddltime.SelectedValue.ToString() + "12:00:00")
        //    {

        //    }
        //}

        //if (txtMobileNum.Text.Trim().ToString().Length != 11 && !strSourceNumtest(txtMobileNum.Text.Trim().ToString()))
        if (txtMobileNum.Text.Trim().ToString().Length != 11)
        {
            lblCheckMobile.Text = "手机格式不正确";
            return;
        }

        if (int.Parse(txtage.Text.Trim().ToString()) > 200)
        {
            lblChecktxtage.Text = "患者年龄过大";
            return;
        }


        if (txtContent.Text.Trim().ToString() != "")
        {
            //50个汉字 100个字符
            if (Text_Length(txtContent.Text.ToString()) > 100)
            {
                lblChecktxtContent.Text = "留言内容不能超过50个汉字(100个字符)";
                return;
            }
        }

        string strError = "";
        string strContent = "";

        if (lblShowTimeCheck.Text == "可预约")
        {
            //检查是否已有同样的号码、姓名、日期及时段记录，若有则重新发送短信
            Cisoft.YiWu.BLL.PlanInfoBO bllplaninfoedit = new Cisoft.YiWu.BLL.PlanInfoBO();
            Cisoft.YiWu.Model.PlanInfoMO modelplaninfoedit = new Cisoft.YiWu.Model.PlanInfoMO();
            string strhaveplanid = "";
            strhaveplanid = bllplaninfoedit.CheckHaveByNameNumDaySliceid(txtMobileNum.Text.Trim().ToString(), Name.Text.Trim().ToString().Replace("'", ""), System.Convert.ToDateTime(ddlbookday.SelectedValue.ToString()), int.Parse(ddltime.SelectedValue.ToString()));

            if (strhaveplanid != "")
            {
                //存在记录判断状态
                modelplaninfoedit = bllplaninfoedit.GetModel(int.Parse(strhaveplanid));
                if (modelplaninfoedit.PI_PlanStatus == 0)
                {

                    modelplaninfoedit.PI_PlanStatus = 1;

                    //性别
                    modelplaninfoedit.PI_Sex = ddlSex.SelectedValue.ToString();
                    //年龄
                    modelplaninfoedit.PI_Age = txtage.Text.Trim().ToString();
                    //手机
                    modelplaninfoedit.PI_MobileNum = txtMobileNum.Text.Trim().ToString();
                    //预约留言
                    modelplaninfoedit.PI_Summary = HtmlEncode(txtContent.Text.ToString().Replace("'", ""));
                    string strtip = "";
                    try
                    {
                        if (bllplaninfoedit.Update(modelplaninfoedit) > 0)
                        {
                        }
                        else
                        { }
                    }
                    catch (Exception ex)
                    {
                        strtip = ex.Message.ToString();
                    }

                    if (strtip != "")
                    {
                        PageError("新增预约失败！错误信息如下：" + strtip, "PlanAdd.aspx?hospitalid=" + Request.QueryString["hospitalid"].ToString(), "返回重试", "");
                    }
                    else
                    {
                        PageRight("新增预约成功！", "PlanManage.aspx", "继续操作", "");
                    }



                    ////关闭后重试
                    //if (pnlShowFile.Visible == false)
                    //{
                    //    //再次发送短信
                    //    strContent = "您预约" + lblHospitalName.Text.ToString() + "的" + lblDepartmentName.Text.ToString() + "。时间为：" + Cisoft.IntegrationSystem.Common.DateTimeHelper.GetChinaShortDateAndWeeky(System.Convert.ToDateTime(ddlbookday.SelectedValue.ToString())) + ddltime.SelectedItem.Text.ToString() + "以下为您的手机验证码，请填写到网站上进行预约确认" + modelplaninfoedit.PI_Code;
                    //    int flag = 0;

                    //    try
                    //    {
                    //        SendMessage(txtMobileNum.Text.Trim().ToString(), strContent);
                    //    }
                    //    catch (Exception ex)
                    //    {
                    //        flag = 1;
                    //        strError = ex.Message;
                    //    }
                    //    if (flag == 1)
                    //    {
                    //        PageError("预约校验码发送短信失败！错误信息如下：" + strError, "content.aspx?hospitalid=" + Request.QueryString["hospitalid"].ToString() + "&departmentid=" + Request.QueryString["departmentid"].ToString(), "返回重试", "");
                    //    }
                    //    else
                    //    {
                    //        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "", "alert('校验码短信发送成功！请注意接收！');", true);
                    //        pnlShowFile.Visible = true;
                    //        return;
                    //    }
                    //}
                    //else
                    //{
                    //    if (txtcode.Text.ToString().ToLower() == modelplaninfoedit.PI_Code.ToString().ToLower())
                    //    {
                    //        modelplaninfoedit.PI_PlanStatus = 1;

                    //        //性别
                    //        modelplaninfoedit.PI_Sex = ddlSex.SelectedValue.ToString();
                    //        //年龄
                    //        modelplaninfoedit.PI_Age = txtage.Text.Trim().ToString();
                    //        //手机
                    //        modelplaninfoedit.PI_MobileNum = txtMobileNum.Text.Trim().ToString();
                    //        //预约留言
                    //        modelplaninfoedit.PI_Summary = HtmlEncode(txtContent.Text.ToString().Replace("'", ""));

                    //        if (bllplaninfoedit.Update(modelplaninfoedit) > 0)
                    //        {

                    //            #region InfoArray数组生成

                    //            string[] strInfoarray = new string[9];

                    //            //预约时间
                    //            strInfoarray[0] = Cisoft.IntegrationSystem.Common.DateTimeHelper.GetChinaShortDateAndWeeky(System.Convert.ToDateTime(ddlbookday.SelectedValue.ToString())) + ddltime.SelectedItem.Text.ToString();
                    //            //患者姓名
                    //            strInfoarray[1] = modelplaninfoedit.PI_Name.ToString();
                    //            //性别
                    //            strInfoarray[2] = modelplaninfoedit.PI_Sex.ToString();
                    //            //年龄
                    //            strInfoarray[3] = modelplaninfoedit.PI_Age.ToString();
                    //            //联系地址
                    //            //strInfoarray[4] = add.Text.Trim().ToString();
                    //            strInfoarray[4] = "";
                    //            //手机
                    //            strInfoarray[5] = modelplaninfoedit.PI_MobileNum.ToString();
                    //            //预约医院
                    //            strInfoarray[6] = lblHospitalName.Text.Trim().ToString();
                    //            //预约留言
                    //            strInfoarray[7] = txtContent.Text.ToString().Replace("'", "").ToString();
                    //            //预约科类
                    //            strInfoarray[8] = lblDepartmentName.Text.Trim().ToString();
                    //            ////医生
                    //            ////strInfoarray[9] = ddldoctors.SelectedValue.ToString();
                    //            //strInfoarray[9] = "";
                    //            ////地址
                    //            //strInfoarray[10] = "";

                    //            //放入Session
                    //            Session["InfoArray"] = strInfoarray;

                    //            #endregion

                    //            Response.Redirect("success.aspx");
                    //        }
                    //        else
                    //        {
                    //            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "", "alert('提交校验码异常，请联系管理员！');", true);
                    //            return;
                    //        }
                    //    }
                    //    else
                    //    {
                    //        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "", "alert('校验码不符，请重试！');", true);
                    //        pnlShowFile.Visible = true;
                    //        return;
                    //    }
                    //}


                }
                else
                {
                    if (modelplaninfoedit.PI_PlanStatus == 1 || modelplaninfoedit.PI_PlanStatus == 2)
                    {
                        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "", "alert('已经成功预约！请勿重复预约');", true);
                        return;
                    }
                }
            }
            else
            {

                //新增预约记录
                Cisoft.YiWu.BLL.PlanInfoBO bllplaninfoAdd = new Cisoft.YiWu.BLL.PlanInfoBO();
                Cisoft.YiWu.Model.PlanInfoMO modelplaninfoAdd = new Cisoft.YiWu.Model.PlanInfoMO();

                //预约时间
                modelplaninfoAdd.PI_PlanTime = System.Convert.ToDateTime(ddlbookday.SelectedValue.ToString());
                //患者姓名
                modelplaninfoAdd.PI_Name = Name.Text.Trim().ToString().Replace("'", "");
                //性别
                modelplaninfoAdd.PI_Sex = ddlSex.SelectedValue.ToString();
                //年龄
                modelplaninfoAdd.PI_Age = txtage.Text.Trim().ToString();
                //手机
                modelplaninfoAdd.PI_MobileNum = txtMobileNum.Text.Trim().ToString();
                //预约时段
                modelplaninfoAdd.PI_PlanSliceID = int.Parse(ddltime.SelectedValue.ToString());
                //预约留言
                modelplaninfoAdd.PI_Summary = HtmlEncode(txtContent.Text.ToString().Replace("'", ""));
                modelplaninfoAdd.PI_Code = CreateRandomCode(4);
                modelplaninfoAdd.PI_CreateTime = DateTime.Now;

                //电话预约
                modelplaninfoAdd.PI_PlanStatus = 2;
                //主键
                modelplaninfoAdd.PI_PlanID = bllplaninfoAdd.GetMaxId();


                string strtip = "";
                try
                {

                    if (bllplaninfoAdd.Add(modelplaninfoAdd) > 0)
                    {
                        ////新增记录成功，发送校验码短信
                        //strContent = "您预约" + lblHospitalName.Text.ToString() + "的" + lblDepartmentName.Text.ToString() + "。时间为：" + Cisoft.IntegrationSystem.Common.DateTimeHelper.GetChinaShortDateAndWeeky(System.Convert.ToDateTime(ddlbookday.SelectedValue.ToString())) + ddltime.SelectedItem.Text.ToString() + "以下为您的手机验证码，请填写到网站上进行预约确认" + modelplaninfoAdd.PI_Code;
                        //int flag = 0;

                        //try
                        //{
                        //    SendMessage(txtMobileNum.Text.Trim().ToString(), strContent);
                        //}
                        //catch (Exception ex)
                        //{
                        //    flag = 1;
                        //    strError = ex.Message;
                        //}
                        //if (flag == 1)
                        //{
                        //    PageError("预约校验码发送短信失败！错误信息如下：" + strError, "content.aspx?hospitalid=" + Request.QueryString["hospitalid"].ToString() + "&departmentid=" + Request.QueryString["departmentid"].ToString(), "返回重试", "");
                        //}
                        //else
                        //{
                        //    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "", "alert('校验码短信发送成功！请注意接收！');", true);
                        //    pnlShowFile.Visible = true;
                        //    return;
                        //}
                    }
                    else
                    {
                        strtip = "记录新增异常，请联系管理员";
                    }
                }
                catch (Exception ex)
                {
                    strtip = ex.Message.ToString();
                }

                if (strtip != "")
                {
                    PageError("新增预约失败！错误信息如下：" + strtip, "PlanAdd.aspx?hospitalid=" + Request.QueryString["hospitalid"].ToString(), "返回重试", "");
                }
                else
                {
                    PageRight("新增预约成功！", "PlanManage.aspx", "继续操作", "");
                }
            }

        }
        else
        {
            ScriptManager.RegisterStartupScript(Page, Page.GetType(), "", "alert('" + lblShowTimeCheck.Text.ToString() + "');", true);
            return;
        }


        //string strurl = HttpContext.Current.Server.MapPath("~/xmlconfig/yewutest/yewutestConfiguation.xml");
        //strurl = HttpContext.Current.Server.MapPath("~/xmlconfig/EMAConfig/EMAConfiguation.xml"); ApplicationID

        //strContent = "您已预约" + lblHospitalName.Text.ToString() + "的" + lblDepartmentName.Text.ToString() + "。时间为：" + Cisoft.IntegrationSystem.Common.DateTimeHelper.GetChinaShortDateAndWeeky(ddlbookday.SelectedValue.ToString()) + ddltime.SelectedValue.ToString() + "您前面还有" + Cisoft.IntegrationSystem.Common.XMLHelper.GetConfigValue("Num", strurl) + "位患者。";





        #region InfoArray数组生成

        //string[] strInfoarray = new string[11];

        ////预约时间
        //strInfoarray[0] = Cisoft.IntegrationSystem.Common.DateTimeHelper.GetChinaShortDateAndWeeky(ReservationTime) + ddltime.SelectedValue.ToString();
        ////患者姓名
        //strInfoarray[1] = Name.Text.Trim().ToString();
        ////性别
        //strInfoarray[2] = ddlSex.SelectedValue.ToString();
        ////年龄
        //strInfoarray[3] = txtage.Text.Trim().ToString();
        ////联系地址
        ////strInfoarray[4] = add.Text.Trim().ToString();
        //strInfoarray[4] = "";
        ////手机
        //strInfoarray[5] = txtMobileNum.Text.Trim().ToString();
        ////预约医院
        //strInfoarray[6] = lblHospitalName.Text.Trim().ToString();
        ////预约留言
        //strInfoarray[7] = txtContent.Text.ToString();
        ////预约科类
        //strInfoarray[8] = lblDepartmentName.Text.Trim().ToString();
        ////医生
        ////strInfoarray[9] = ddldoctors.SelectedValue.ToString();
        //strInfoarray[9] = "";
        ////地址
        //strInfoarray[10] = "";

        ////放入Session
        //Session["InfoArray"] = strInfoarray;

        #endregion






        //int tnum = int.Parse(Cisoft.IntegrationSystem.Common.XMLHelper.GetConfigValue("Num", strurl).ToString());

        //if (tnum > 11)
        //{
        //    tnum = 2;
        //}
        //else
        //{
        //    tnum = tnum + 1;
        //}

        //try
        //{
        //    Cisoft.IntegrationSystem.Common.XMLHelper.SetConfigValue("Num", strurl, tnum.ToString());
        //}
        //catch
        //{

        //}

        //PageRight("网上预定成功，请等待确认短信","index.html","返回首页","");









    }
    #endregion

    #region  验证手机号码
    /// <summary>
    /// 验证手机号码
    /// </summary>
    /// <param name="t"></param>
    /// <returns></returns>
    public bool strSourceNumtest(string t)
    {

        bool re = false;
        if (t.Length == 11 && (t.Substring(0, 3) == "133" || t.Substring(0, 3) == "153" || t.Substring(0, 3) == "189"))
        {
            re = true;
        }


        return re;
    }
    #endregion

    #region 长度
    /// <summary>   
    /// 计算文本长度，区分中英文字符，中文算两个长度，英文算一个长度
    /// </summary>
    /// <param name="Text">需计算长度的字符串</param>
    /// <returns>int</returns>
    public int Text_Length(string Text)
    {
        int len = 0;

        for (int i = 0; i < Text.Length; i++)
        {
            byte[] byte_len = System.Text.Encoding.Default.GetBytes(Text.Substring(i, 1));
            if (byte_len.Length > 1)
                len += 2;  //如果长度大于1，是中文，占两个字节，+2
            else
                len += 1;  //如果长度等于1，是英文，占一个字节，+1
        }

        return len;
    }
    #endregion


    #region 返回事件
    protected void ibtnCannel_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("PlanManage.aspx");
    }
    #endregion

    #region 日期选择事件
    protected void ddlbookday_SelectedIndexChanged(object sender, EventArgs e)
    {
        //预约时段人数状态
        lblShowTimeCheck.Text = CheckBookNum(int.Parse(lblDepartmentID.Text), System.Convert.ToDateTime(ddlbookday.SelectedValue.ToString()), int.Parse(ddltime.SelectedValue.ToString()));
    }
    #endregion

    #region 时间段选择事件
    protected void ddltime_SelectedIndexChanged(object sender, EventArgs e)
    {
        //预约时段人数状态
        lblShowTimeCheck.Text = CheckBookNum(int.Parse(lblDepartmentID.Text), System.Convert.ToDateTime(ddlbookday.SelectedValue.ToString()), int.Parse(ddltime.SelectedValue.ToString()));
    }
    #endregion

    #region HTML编码 public static string HtmlEncode(string str)
    /// <summary>
    /// HTML编码
    /// </summary>
    /// <param name="str"></param>
    /// <returns></returns>
    public static string HtmlEncode(string str)
    {
        if (!string.IsNullOrEmpty(str))
        {
            str = str.Replace("<", "& lt;");
            str = str.Replace(">", "& gt;");
            str = str.Replace(" ", "& nbsp;");
            str = str.Replace("'", "& #39;");
            str = str.Replace("\"", "& quot;");
            str = str.Replace("\r\n", "<br>");
            str = str.Replace("\n", "<br>");
        }
        return str;
    }
    #endregion

    #region HTML解码 public static string HtmlDecode(string value)
    /// <summary>
    /// HTML解码
    /// </summary>
    /// <param name="value"></param>
    /// <returns></returns>
    public static string HtmlDecode(string value)
    {
        if (!string.IsNullOrEmpty(value))
        {
            value = value.Replace("<br>", "\n");
            value = value.Replace("& gt;", ">");
            value = value.Replace("& lt;", "<");
            value = value.Replace("& nbsp;", " ");
            value = value.Replace("& #39;", "'");
            value = value.Replace("& quot;", "\"");
        }
        return value;
    }
    #endregion

    #region 生成随机码 private string CreateRandomCode(int codeCount)
    /// <summary>
    /// 生成随机码
    /// </summary>
    /// <param name="codeCount"></param>
    /// <returns></returns>
    private string CreateRandomCode(int codeCount)
    {
        string allChar = "2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,J,K,M,N,P,Q,R,S,T,W,X,Y,Z";
        string[] allCharArray = allChar.Split(',');
        string randomCode = "";
        int temp = -1;

        Random rand = new Random();
        for (int i = 0; i < codeCount; i++)
        {
            if (temp != -1)
            {
                rand = new Random(i * temp * ((int)DateTime.Now.Ticks));
            }
            int t = rand.Next(29);
            if (temp == t)
            {
                return CreateRandomCode(codeCount);
            }
            temp = t;
            randomCode += allCharArray[t];
        }
        return randomCode;
    }
    #endregion

    #region 科室切换
    /// <summary>
    /// 科室切换
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ddlDep_SelectedIndexChanged(object sender, EventArgs e)
    {
        lblDepartmentID.Text = ddlDep.SelectedValue.ToString();
        lblDepartmentName.Text = ddlDep.SelectedItem.Text.ToString();
        lblShowTimeCheck.Text = CheckBookNum(int.Parse(lblDepartmentID.Text), System.Convert.ToDateTime(ddlbookday.SelectedValue.ToString()), int.Parse(ddltime.SelectedValue.ToString()));
    }
    #endregion
}
